package Test08;

//网络编程

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//TCP协议，接收数据
//服务器端（Server）
//中文乱码问题

public class Test15 {
    public static void main(String[] args) throws IOException {

        //1、创建ServerSocket对象
        ServerSocket ss = new ServerSocket(33333);

        //2、监听客户端的连接
        Socket socket = ss.accept();

        //3、从连接通道获取输入流
        /*InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);//转换流解决中文乱码问题
        BufferedReader br = new BufferedReader(isr);//缓冲流提高效率*/

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        //4、读取数据
        int b;
        while ((b = br.read()) != -1) {
            System.out.print((char) b);
        }

        //5、释放资源
        socket.close();
        ss.close();
    }
}
